
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
      height:"",
    account:"",
      btnBool:false,
      userInfo:"",
  },

  /**
   * 生命周期函数--监听页面加载
   */
    onLoad: function (options) {
      var that = this;
      this.setData({
          userInfo:wx.getStorageSync('userInfo'),
      })
      console.log(wx.getStorageSync('userInfo'))
      wx.getSystemInfo({
          success:function (res) {
              that.setData({
                  height:res.windowHeight,
                  width:res.windowWidth,
              })

          }
      });
    },
    userPhone:function(e){
      this.setData({
          account:e.detail.value
      });
    },
    testOk:function(){
      var that = this;
        wx.showModal({
            content: '确认使用['+this.data.account+'作为支付宝佣金发放账户吗',
            confirmText: "确认无误",
            cancelText: "取消",
            confirmColor:'#2296EB',
            success: function (res) {
                if (res.confirm) {
                    wx.request({
                        url: app.globalData.APIURL + '/vending-admin/admin/user/fillPayeeAccount',
                        data: {
                            token:app.globalData.token,
                            payee_account:that.data.account
                        },
                        header: {
                            'content-type': 'application/json' // 默认值
                        },
                        success: function (res) {

                            console.log(res.data);
                            if(app.requestEro(res.data.success,res.data.msg)){
                                wx.showModal({
                                    content: '测试佣金0.1元已发放你的支付宝账户，请注意查收',
                                    confirmColor:'#2296EB',
                                    showCancel: false,
                                    success: function (res) {
                                        if (res.confirm) {
                                          that.setData({
                                              btnBool:true
                                          });
                                        }
                                    }
                                })
                            }

                        },
                        fail: function (err) {

                            console.log(err)
                        }
                    })
                }
            }
        })


    },
    accountOk:function(){
      var that = this;
        wx.showModal({
            content: '账户绑定后不可修改，确认绑定支付宝账户['+this.data.account+']吗？',
            confirmColor:'#D20F27',
            success: function(res) {
                if (res.confirm) {
                    wx.showLoading({
                        title: '绑定中，请稍侯',
                    });
                    wx.request({
                        url: app.globalData.APIURL + '/vending-admin/admin/user/confirmPayeeAccount',
                        data: {
                            token:app.globalData.token,
                            payee_account:that.data.account
                        },
                        header: {
                            'content-type': 'application/json' // 默认值
                        },
                        success: function (res) {
                            wx.hideLoading();
                            console.log(res.data);
                            if(app.requestEro(res.data.success,res.data.msg)){
                                that.searchState();
                                wx.showModal({
                                    content: '账户绑定成功，点击确认返回！',
                                    showCancel: false,
                                    success: function (res) {
                                        if (res.confirm) {
                                          //绑定成功之后查询绑定状态，更改存储地方

                                            wx.navigateBack();

                                        }
                                    }
                                })
                            }

                        },
                        fail: function (err) {
                            wx.hideLoading();
                            console.log(err)
                        }
                    })
                } else if (res.cancel) {

                }
            }
        })

    },
    searchState:function(){
      var that = this;
        wx.request({
            url: app.globalData.APIURL + '/vending-admin/admin/user/getUserFast',
            data: {
                token:app.globalData.token,
                searchStr:that.data.userInfo.username
            },
            header: {
                'content-type': 'application/json' // 默认值
            },
            success: function (res) {

                console.log(res.data);
                if(app.requestEro(res.data.success,res.data.msg)){
                  app.globalData.userInfo = res.data.records.list[0];
                    wx.setStorageSync('userInfo', res.data.records.list[0]);

                }

            },
            fail: function (err) {

                console.log(err)
            }
        })
    },
    changeAccount:function(){
      this.setData({
          btnBool:false,
          userInfo:{payee_state:3}
      });
    },
    cancelAccount:function(){
        this.setData({
            btnBool:true,
        });
    },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})